// Extend.js (http://code.google.com/p/extendjs/)
// Copyright 2010 Shumpei Shiraishi All rights reserved.
// Licensed under the MIT license.

(function(_global) {
    var NATIVE_METHODS_NUMBER = [
	"toString", "toLocaleString", "valueOf", "toFixed", "toExponential", "toPrecision", "toJSON"
    ];
    var NATIVE_METHODS_MATH = [
	"abs", "acos", "asin", "atan", "atan2", "ceil",
	"cos", "exp", "floor", "log", "pow", "round",
	"sin", "sqrt", "tan"
    ];
    X.extend("Number", function(value) {
	return typeof value === "number";
    });
    X.Number.extend({
	times: function(fn, ctx) {
	    var count = this.__val;
	    for (var i = 0; i < count; i++) {
		fn.call(ctx, i);
	    }
	},
	padLeft: function(count, ch) {
	    if (ch === undefined) {
		ch = "0";
	    }
	    return new X.String(String(this.__val)).padLeft(count, ch);
	},
	padRight: function(count, ch) {
	    if (ch === undefined) {
		ch = "0";
	    }
	    return new X.String(String(this.__val)).padRight(count, ch);
	}
    });
    (function addMathMethods() {
	for (var i = 0, n = NATIVE_METHODS_MATH.length; i < n; i++) {
	    var methodName = NATIVE_METHODS_MATH[i];
	    var method = Math[methodName];
	    if (typeof method === "function") {
		X.Number.extend(methodName, (function(_method) {
		    return function() {
			return _method.call(Math, this.__val);
		    };
		})(method));
	    }
	}
    })();
    X.Number.mixin(Number.prototype, NATIVE_METHODS_NUMBER);
})(this);
